<?php

require_once('rb.php');
R::setup('mysql:host=ftp.giemiebier.nl:3306;dbname=personify', 'school', 'admin123');

$m = new MongoClient('mongodb://ftp.giemiebier.nl');

$db = $m->chatdb;
$user_chats = $db->chat;
//echo $pagetree[2];
$cursor = $user_chats->find(["_id" => new MongoId($pagetree[2])]);
//var_dump($cursor);
foreach ($cursor as $document) {
    //echo "test";

    foreach ($document["users"] as $user) {
        $tmp = array();
        $tmp["email"] = $user["email"];
        $tmp["id"] = $user["id"];
        $return["users"][] = $tmp;
    }
}

$return['valid'] = true;
echo json_encode($return);